/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.entity;

import it.polimi.registration.business.security.control.PasswordEncrypter;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author miglie
 */
@Entity
@Table(name = "USERS")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @Id
    @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
            message = "invalid email")
    @NotNull(message = "May not be empty")
    private String email;
    
    @NotNull(message = "May not be empty")
    private String password;
    
    @NotNull(message = "May not be empty")
    private String groupName;
    
    @NotNull(message = "May not be empty")
    private String name;
    
    @NotNull(message = "May not be empty")
    private String surname;
    
    @Temporal(TemporalType.DATE)
    private Date dateOfBirth;
    
    @Basic(optional = false)
    private boolean calendarVisibility; //false = private - true = public
    
    @Basic(optional = false)
    private boolean notificationSetting;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "creator")
    private Collection<Event> eventCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Invite> inviteCollection;    
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
    private Collection<GroupFriend> groupLabelCollection;    
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private Collection<SystemNotification> systemNotificationCollection;    
   
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "receiver")
    private Collection<Friend> friendshipNotificationReceiver;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sender")
    private Collection<Friend> friendshipNotificationSender;   
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private Collection<Personalize> personalizeCollection;
    
    public User() {
    }

    public User(String name,String surname,String email, String password) {
        this.name= name;
        this.surname=surname;
        this.email = email;
        this.password = password;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getGroupName() {
        return groupName;
    }
    
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = PasswordEncrypter.encryptPassword(password);
    }
    
    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public boolean getCalendarVisibility() {
        return calendarVisibility;
    }

    public void setCalendarVisibility(boolean calendarVisibility) {
        this.calendarVisibility = calendarVisibility;
    }

    public boolean getNotificationSetting() {
        return notificationSetting;
    }

    public void setNotificationSetting(boolean notificationSetting) {
        this.notificationSetting = notificationSetting;
    }
    
    @XmlTransient
    public Collection<Event> getEventCollection() {
        return eventCollection;
    }

    public void setEventCollection(Collection<Event> eventCollection) {
        this.eventCollection = eventCollection;
    }
    
    @XmlTransient
    public Collection<Invite> getInviteCollection() {
        return inviteCollection;
    }

    public void setInviteCollection(Collection<Invite> inviteCollection) {
        this.inviteCollection = inviteCollection;
    }
    
    @XmlTransient
    public Collection<GroupFriend> getGroupLabelCollection() {
        return groupLabelCollection;
    }

    public void setGroupLabelCollection(Collection<GroupFriend> groupLabelCollection) {
        this.groupLabelCollection = groupLabelCollection;
    }
    
    @XmlTransient
    public Collection<SystemNotification> getSystemNotificationCollection() {
        return systemNotificationCollection;
    }

    public void setSystemNotificationCollection(Collection<SystemNotification> systemNotificationCollection) {
        this.systemNotificationCollection = systemNotificationCollection;
    }
   
    @XmlTransient
    public Collection<Friend> getFriendshipNotificationReceiver() {
        return friendshipNotificationReceiver;
    }

    public void setFriendshipNotificationReceiver(Collection<Friend> friendshipNotification) {
        this.friendshipNotificationReceiver = friendshipNotification;
    }

    @XmlTransient
    public Collection<Friend> getFriendshipNotificationSender() {
        return friendshipNotificationSender;
    }

    public void setFriendshipNotificationSender(Collection<Friend> friendshipNotificationSender) {
        this.friendshipNotificationSender = friendshipNotificationSender;
    }
   
    
    @XmlTransient
    public Collection<Personalize> getPersonalizeCollection() {
        return personalizeCollection;
    }

    public void setPersonalizeCollection(Collection<Personalize> personalizeCollection) {
        this.personalizeCollection = personalizeCollection;
    }

}
